#include <process.h>
#include <debug.h>
#include <list.h>
#include <physmem.h>
#include <io.h>
#include <uvmm.h>

int sys_exit(int status){
         cli ;
       int nb_pt ;
        __u32 pd_paddr, kstack ;
       struct page_table * pt_to_del ;

            
        kstack = paging_virtual_to_physical(page_directory, current->kstack.esp0 - PAGE_SIZE);
       physmem_unref_physpage(kstack);
        kvmm_free(kstack);
     

    // uvmm_delete_as(current->address_space);

     /*Delete directory of pages*/
     pd_paddr = current->regs.cr3 ;
     physmem_unref_physpage(pd_paddr);
     uvmm_delete_as(current->address_space);

       num_proc--;
       /* Change the task state and set its exit status. */
      p_list[current->pid].state =  PROC_STOPPED ;
      p_list[current->pid].exit_status = status;
    
      sti;
   
      schedule(true);      
       return 0 ;


}
